package com.minhua.jijiehao2.mainframe.mine.problemactivity.impl

import com.minhua.jijiehao2.R
import com.minhua.jijiehao2.base.BaseActivity
import com.minhua.jijiehao2.base.adapter.ViewHolder
import com.minhua.jijiehao2.base.adapter.abslistview.BaseExpCommonAdapter
import com.minhua.jijiehao2.bean.QuestionBean
import com.minhua.jijiehao2.mainframe.mine.problemactivity.imp.IProblemView
import kotlinx.android.synthetic.main.activity_problem.*

class ProblemActivity : BaseActivity<IProblemView, ProblemPresenter>(), IProblemView {

    override fun getLayoutId(): Int = R.layout.activity_problem

    override fun getPresenter(): ProblemPresenter = ProblemPresenter()

    private var adapter: BaseExpCommonAdapter<QuestionBean.ProblemGeneralDetailsBean, QuestionBean>? = null
    private val data = arrayListOf<QuestionBean>()

    override fun initView() {
        adapter = object : BaseExpCommonAdapter<QuestionBean.ProblemGeneralDetailsBean, QuestionBean>(this, R.layout.item_question_group, R.layout.item_question_child, data) {
            override fun convertGroup(groupViewHolder: ViewHolder?, group: QuestionBean?) {
                groupViewHolder?.setText(R.id.tvGroup, group?.problem_name)
            }

            override fun convertChild(childViewHolder: ViewHolder?, child: QuestionBean.ProblemGeneralDetailsBean?) {
                childViewHolder?.setText(R.id.tvChild, "\t" + child?.small_sort + "  " + child?.problem_answer)
            }
        }

        elvContent.setAdapter(adapter)
    }

    override fun initData() {
        super.initData()
        mPresenter.getProblemList()
    }

    override fun onProblemSuccess(list: List<QuestionBean>) {
        data.clear()
        data.addAll(list)
        for (i in data.indices) {
            elvContent.expandGroup(i)
            elvContent.collapseGroup(i)
        }
    }
}
